import datetime
import numpy as np; np.random.seed(0)
import seaborn as sb;
from matplotlib import pyplot as plt
import random

def delta_date( start_date, end_date):
    """
    计算起始与结束日期长度，是结束-起始，所以一般为正。用做判定日期大小需要注意前后顺序
    :param start_date:
    :param end_date:
    :return:
    """
    start = datetime.datetime.strptime(start_date, "%Y-%m-%d")
    end = datetime.datetime.strptime(end_date, "%Y-%m-%d")
    delta_day = (end - start).days
    return delta_day

def dateAdd(start_date,days):
    """
    最正确的日期加法
    :param start_date:
    :param days:
    :return:
    """
    d=datetime.datetime.strptime(start_date,'%Y-%m-%d')
    delta = datetime.timedelta(days=days)
    n_days = d + delta
    return (n_days.strftime('%Y-%m-%d'))

def getEveryDay(start_date, end_date):
    date_list = []
    start = datetime.datetime.strptime(start_date, "%Y-%m-%d")
    end = datetime.datetime.strptime(end_date, "%Y-%m-%d")
    while start <= end:
        date_str = start.strftime("%Y-%m-%d")
        date_list.append(date_str)
        start += datetime.timedelta(days=1)
    return date_list

def clip_list(a,c):  #a为原列表，c为等分长度
    clip_back=[]
    if len(a)>c:
        for i in range(int(len(a) / c)):
            # print(i)
            clip_a = a[c * i:c * (i + 1)]
            clip_back.append(clip_a)
            # print(clip_a)
        # last 剩下的单独为一组
        last = a[int(len(a) / c) * c:]
        if last:
            clip_back.append(last)
    return clip_back
ori_today=datetime.datetime.today()
today=ori_today.strftime("%Y-%m-%d")

now = datetime.datetime.now()
this_week_start = (now - datetime.timedelta(days=now.weekday())).strftime("%Y-%m-%d")
this_week_end = (now + datetime.timedelta(days=6 - now.weekday())).strftime("%Y-%m-%d")
last_last_last_week_start=dateAdd(this_week_start,-7*3)
next_week_end=dateAdd(this_week_end,7)
all_dates=getEveryDay(last_last_last_week_start,next_week_end)
print(all_dates)
mo_data=[ i for i in range(len(all_dates))]
cs= clip_list(all_dates,7)
cd=clip_list(mo_data,7)
print(cs)
ncs=np.array(cs)
ncd=np.array(cd)
tncs=ncs.T
tncd=ncd.T
# print(tncs)
# print(tncd)
# nd=np.concatenate(tncs,tncd,axis=1)
nd=np.array([tncs.tolist(),tncd.tolist()])
print(nd)

plt.rcParams['font.sans-serif'] = ['SimHei']  # 解决中文显示问题-设置字体为黑体
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题
#sb.set()
# uniform_data = np.random.rand(10, 12)
# print(uniform_data)
# ax = sb.heatmap(uniform_data)
# plt.show()
ax=sb.heatmap(tncd,cmap='YlOrBr',linewidths=.5, annot=True, fmt="d",square=True,cbar_kws={"orientation": "vertical"})#cbar_kws={"orientation": "horizontal"}{"orientation": "vertical"}
print(nd.shape)
# ax.text(j, i, int(day), ha='center', va='center')
# r,c=nd.shape
# for ro in range(r):
#     for cl in range(c):
#         ax.text(cl, ro, 222, ha='center', va='center_baseline')

# ax.xaxis.tick_top()  #水平索引


ax.set_yticklabels(['星期一','星期二','星期三','星期四','星期五','星期六','星期日'], rotation=1)#, rotation=90
plt.show()